/**
 * 模态框
 */
module.exports = function($scope, $state, $stateParams, $modalInstance, items, $resource,$modal){
    console.log(items);
    console.log('上面是items')
                    $scope.b=items;
                    $scope.obj={};
                    
					
                    
    
    // $resource('/api/ac/lc/supplierProductService/findSupplierProductInfo', {}, {}).
	// 		save({product_id : items.id}, function(res){
				
    //             if(res.errcode === 0 || res.errcode === 10003){
					
    //             }else{
    //                 alert(res.errmsg);
    //             }
    //         });

            $scope.search=function(){

				if($scope.date.lable){
                    $scope.tour_date=date2str2($scope.date.lable);
                }else{
                    $scope.tour_date=''
                }
                if($scope.date1.lable){
                    $scope.tour_date_two=date2str2($scope.date1.lable);
                }else{
                    $scope.tour_date_two=''
                }

                if($scope.date.lable!=null && $scope.date1.lable!=null){
                    if($scope.tour_date>$scope.tour_date_two){
                        alert('开始日期不能大于结束日期');
                        return;
                    }
                }
                if($scope.date.lable){
                    if(!$scope.date1.lable){
                        alert('开始和结束日期必须同时输入进行搜索')
                        return;
                    }
                }
                if($scope.date1.lable){
                    if(!$scope.date.lable){
                        alert('开始和结束日期必须同时输入进行搜索')
                        return;
                    }
                }  
                $scope.allarr=[];
                for(var i = 0;i<$scope.b.length;i++){					
						$scope.allarr.push({product_id:$scope.b[i].id,tour_date:$scope.tour_date,tour_date_two:$scope.tour_date_two})
						
						for(var j = 0;j<$scope.b[i].codeInfoList.length;j++){
							$scope.allarr.push({product_id:$scope.b[i].codeInfoList[j].id,tour_date:$scope.tour_date,tour_date_two:$scope.tour_date_two})
						}
					}
					
					$scope.obj['idarr']=$scope.allarr;
                    console.log($scope.obj);
				$resource('/api/ac/lc/lineStatisticsListService/findOrderInfoList', {}, {}).save($scope.obj, function(res){
                if(res.errcode === 0 || res.errcode === 10003){
                    console.log(res);
                    console.log('上面是res')
					$scope.a=res.data;
                	$scope.a.callmoney=$scope.a.callmoney/100;
                    $scope.a.salemoney=$scope.a.salemoney/100;
                    
                }else{
                    alert(res.errmsg);
                }
            });
			}
            
            $scope.date = {
                // 'lable': date2str2(new Date()),
                'value': date2str(new Date()),
                'opened': false
            }


             $scope.dateOpen = function ($event, item) {
                $event.preventDefault();
                $event.stopPropagation();
                item.opened = true;
            };

            $scope.date1 = {
                // 'lable': date2str2(new Date()),
                'value': date2str(new Date()),
                'opened': false
            }


             $scope.dateOpen1 = function ($event, item) {
                $event.preventDefault();
                $event.stopPropagation();
                item.opened = true;
            };

            function date2str2(d) {
                if (d === undefined) {
                    return "";
                }
                var month = (d.getMonth() + 1).toString();
                var day = d.getDate().toString();
                if (month.length == 1) month = '0' + month;
                if (day.length == 1) day = '0' + day;
                return d.getFullYear() + "-" + month + "-" + day;
            }

            function date2str(d) {
                if (d === undefined) {
                    return "";
                }
                var month = (d.getMonth() + 1).toString();
                var day = d.getDate().toString();
                if (month.length == 1) month = '0' + month;
                if (day.length == 1) day = '0' + day;
                return d.getFullYear() + month + day;
            }

            $scope.cancel = function () {  
                $modalInstance.dismiss('cancel'); 
            };
           

            
 
};